#include <QStringListModel>

#include "insertdatawidget.h"

InsertDataWidget::InsertDataWidget( QStringList &stringList, QWidget * parent) 
	:QWidget(parent)
{
	setupUi(this);
	list = &stringList;
	model = new QStringListModel(*list);
	
	connect(addButton,SIGNAL(clicked()),this,SLOT(insert()));
	connect(removeButton,SIGNAL(clicked()),this,SLOT(del()));
	
	listView->setModel(model);	
}

void InsertDataWidget::insert()
{
	int row = listView->currentIndex().row() + 1;
	model->insertRows(row,1);
	
	QModelIndex index = model->index(row);
	listView->setCurrentIndex(index);
	listView->edit(index);
}

void InsertDataWidget::del()
{
	model->removeRows(listView->currentIndex().row(),1);
}

void InsertDataWidget::revert()
{
	model->revert();
	model->setStringList(*list);
}
